//
//  LYTextField.m
//  LYDevelopKit
//
//  Created by 李阳 on 2018/5/25.
//

#import "LYTextField.h"

@implementation LYTextField

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (!self) return nil;
    [self setup];
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setup];
}
- (void)setup
{
    // 设置光标颜色和文字颜色一致
    self.tintColor = self.textColor;
    // 不成为第一响应者
    [self resignFirstResponder];
}

/**
 * 当前文本框聚焦时就会调用
 */
- (BOOL)becomeFirstResponder
{
    // 修改占位文字颜色
    self.placeholderColor = self.textColor;
    return [super becomeFirstResponder];
}
/**
 * 当前文本框失去焦点时就会调用
 */
- (BOOL)resignFirstResponder
{
    // 修改占位文字颜色
    self.placeholderColor = [UIColor grayColor];
    return [super resignFirstResponder];
}

- (void)setPlaceholderColor:(UIColor *)color
{
    [self setValue:color forKeyPath:@"_placeholderLabel.textColor"];
}

/// 按删除键会调用这个方法
//- (void)deleteBackward {
//
//}

@end
